package com.mls.web.controller.education;

import java.util.List;

import com.mls.education.domain.EduCourse;
import com.mls.education.service.IEduCourseService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;
import com.mls.common.annotation.Log;
import com.mls.common.enums.BusinessType;
import com.mls.education.domain.EduCourseType;
import com.mls.education.service.IEduCourseTypeService;
import com.mls.common.core.controller.BaseController;
import com.mls.common.core.domain.AjaxResult;
import com.mls.common.utils.poi.ExcelUtil;
import com.mls.common.core.page.TableDataInfo;

/**
 * 课程类型Controller
 * 
 * @author 管理员
 * @date 2022-02-19
 */
@Controller
@RequestMapping("/education/coursetype")
public class EduCourseTypeController extends BaseController
{
    private String prefix = "education/coursetype";

    @Autowired
    private IEduCourseTypeService eduCourseTypeService;

    @Autowired
    private IEduCourseService eduCourseService;

    @RequiresPermissions("education:coursetype:view")
    @GetMapping()
    public String coursetype()
    {
        return prefix + "/coursetype";
    }

    /**
     * 查询课程类型列表
     */
    @RequiresPermissions("education:coursetype:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(EduCourseType eduCourseType)
    {
        startPage();
        List<EduCourseType> list = eduCourseTypeService.selectEduCourseTypeList(eduCourseType);
        return getDataTable(list);
    }

    /**
     * 导出课程类型列表
     */
    @RequiresPermissions("education:coursetype:export")
    @Log(title = "课程类型", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(EduCourseType eduCourseType)
    {
        List<EduCourseType> list = eduCourseTypeService.selectEduCourseTypeList(eduCourseType);
        ExcelUtil<EduCourseType> util = new ExcelUtil<EduCourseType>(EduCourseType.class);
        return util.exportExcel(list, "课程类型数据");
    }

    /**
     * 新增课程类型
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存课程类型
     */
    @RequiresPermissions("education:coursetype:add")
    @Log(title = "课程类型", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(EduCourseType eduCourseType)
    {
        return toAjax(eduCourseTypeService.insertEduCourseType(eduCourseType));
    }

    /**
     * 修改课程类型
     */
    @RequiresPermissions("education:coursetype:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Integer id, ModelMap mmap)
    {
        EduCourseType eduCourseType = eduCourseTypeService.selectEduCourseTypeById(id);
        mmap.put("eduCourseType", eduCourseType);
        return prefix + "/edit";
    }

    /**
     * 修改保存课程类型
     */
    @RequiresPermissions("education:coursetype:edit")
    @Log(title = "课程类型", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(EduCourseType eduCourseType)
    {
        return toAjax(eduCourseTypeService.updateEduCourseType(eduCourseType));
    }

    /**
     * 删除课程类型
     */
    @RequiresPermissions("education:coursetype:remove")
    @Log(title = "课程类型", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(eduCourseTypeService.deleteEduCourseTypeByIds(ids));
    }

    /**
     * 查询课程类型下的课程
     */
    @RequiresPermissions("education:course:list")
    @GetMapping("/detail/{courseTypeId}")
    public String detail(@PathVariable("courseTypeId") Integer courseTypeId, ModelMap mmap)
    {
        mmap.put("courseType", eduCourseTypeService.selectEduCourseTypeById(courseTypeId));
        mmap.put("courseTypeList", eduCourseTypeService.selectEduCourseTypeList(new EduCourseType()));
        return "education/course/course";
    }
}
